from datetime import datetime
from json import JSONEncoder

from django.core.serializers.json import DjangoJSONEncoder
from django.http import JsonResponse


class myEncoder(DjangoJSONEncoder):
    def default(self,o):
        if isinstance(o,datetime):
            return str(o)

        return super().default(o)

class Reponse(object):
    def __init__(self):
        self.msg = ""
        self.errmsg = ""
        self.status = "error"
        self.data = {}

    def json_response(self):
        return JsonResponse({
            "msg": self.msg,
            "status": self.status,
            "data": self.data,
            "errmsg": self.errmsg
        },encoder=myEncoder)
